package com.chen.servlet;/*
package com.chen.servlet;

import com.chen.entity.UserEntity;
import com.chen.service.UserService;
import com.chen.utils.ChenJdbcUtils;


import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

@WebServlet("/login")
public class LoginUserServlet extends HttpServlet {
    UserService userService = new UserService();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        String phone = req.getParameter("phone");
        userService.strIsEmpty(phone, req, resp);
        String pwd = req.getParameter("pwd");
        userService.strIsEmpty(pwd, req, resp);
        //用jdbc查询SQL语句
        Connection connection = null;
        PreparedStatement statement = null;
        ResultSet resultSet = null;
        try {
            connection = ChenJdbcUtils.getConnection();
            statement = connection.prepareStatement
                    ("select * from chen_user where phone=? and pwd=? and is_delete=0");
            statement.setString(1, phone);
            statement.setString(2, pwd);
            resultSet = statement.executeQuery();
            UserEntity userEntity = userService.getByPhoneUser(phone);
            if (resultSet.next()) {
                //登陆成功
                req.setAttribute("phone", userEntity.getPhone());
                req.getRequestDispatcher("showFlight").forward(req, resp);
            } else {
                //登陆失败
                req.setAttribute("errorMsg", "账号或密码错误");
                req.getRequestDispatcher("error.jsp").forward(req, resp);
            }
        } catch (Exception e) {
            e.printStackTrace();
            req.setAttribute("errorMsg", "系统错误或该用户不存在");
            req.getRequestDispatcher("error.jsp").forward(req, resp);
        } finally {
            ChenJdbcUtils.closeConnection(resultSet, statement, connection);
        }
    }
}
*/
